﻿using System;
using System.Data;
using System.Collections.Generic;
using OnlineManagement.Common;
using OnlineManagement.Model;
using OnlineManagement.DALFactory;
using OnlineManagement.IDAL;
namespace OnlineManagement.BLL.Dal
{
	/// <summary>
	/// Piglets
	/// </summary>
	public partial class Piglets
	{
		private readonly IPiglets dal=DataAccess.CreatePiglets();
        public Piglets()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int PigletID)
        {
            return dal.Exists(PigletID);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(OnlineManagement.Model.Piglets model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int PigletID)
        {

            return dal.Delete(PigletID);
        }
       
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public OnlineManagement.Model.Piglets GetModel(int PigletID,Guid sowID)
        {

            return dal.GetModel(PigletID,sowID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public OnlineManagement.Model.Piglets GetModelByCache(int PigletID,Guid sowID)
        {

            string CacheKey = "PigletsModel-" + PigletID;
            object objModel = OnlineManagement.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(PigletID,sowID);
                    if (objModel != null)
                    {
                        //int ModelCache = OnlineManagement.Common.ConfigHelper.GetConfigInt(Common.PubConstant.DataCacheMins);
                       //设置缓存该数据为5分钟，默认为10分钟
                        int ModelCache = 5;
                        OnlineManagement.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (OnlineManagement.Model.Piglets)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
       
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }


        #endregion  BasicMethod
        #region  ExtensionMethod
        /// <summary>
        /// run procedure to get piglets by hoggeryid
        /// </summary>
        /// <param name="hoggeryId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public DataSet GetPigletsByHoggeryID(int hoggeryId, int pageIndex, int pageSize) {
           return dal.GetPigletsByHoggeryID(hoggeryId, pageIndex, pageSize);
        }
        #endregion  ExtensionMethod
	}
}

